<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" ref="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item prop="key">
        <el-input v-model="dataForm.key" placeholder="姓名/证件号/推荐人" clearable></el-input>
      </el-form-item>
      <el-form-item prop="crewPost">
        <el-select v-model="dataForm.crewPost" placeholder="职务" clearable>
          <el-option
            v-for="item in optionsCrewPost"
            :key="item.id"
            :label="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="certificateLevel">
        <el-select v-model="dataForm.certificateLevel" placeholder="证书等级" clearable>
          <el-option
            v-for="item in optionsCertificateLevel"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <br />
      <el-form-item prop="crewStatus">
        <el-select v-model="dataForm.crewStatus" placeholder="状态" clearable>
          <el-option
            v-for="item in optionsCrewStatus"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="ageFrom">
        <el-input v-model="dataForm.ageFrom" placeholder="年龄范围"></el-input>
      </el-form-item>__
      <el-form-item prop="ageTo">
        <el-input v-model="dataForm.ageTo" placeholder="年龄范围"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="resetForm('dataForm')">重置</el-button>
        <el-button
          v-if="isAuth('generator:crewinfo:save')"
          type="primary"
          @click="addOrUpdateHandle()"
        >新增</el-button>
        <!-- <el-button v-if="isAuth('generator:crewinfo:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
      @row-click="clickTable"
    >
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <!-- <el-table-column
        prop="crewId"
        header-align="center"
        align="center"
        label="船员标识">
      </el-table-column>-->
      <el-table-column prop="crewNum" header-align="center" align="center" label="船员编号"></el-table-column>
      <el-table-column prop="crewName" header-align="center" align="center" label="姓名" width="120"></el-table-column>
      <el-table-column prop="age" header-align="center" align="center" label="年龄"></el-table-column>
      <el-table-column prop="crewPost" header-align="center" align="center" label="职务"></el-table-column>
      <!-- <el-table-column
        prop="nationality"
        header-align="center"
        align="center"
        label="国籍">
      </el-table-column>-->
      <el-table-column prop="certificateLevel" header-align="center" align="center" label="证书等级"></el-table-column>
      <el-table-column prop="phoneNumber" header-align="center" align="center" label="手机号"></el-table-column>
      <el-table-column prop="homeAddress" header-align="center" align="center" label="家庭地址"></el-table-column>
      <el-table-column prop="recommenderId" header-align="center" align="center" label="推荐人"></el-table-column>
      <!-- <el-table-column
        prop="birthPlace"
        header-align="center"
        align="center"
        label="出生地">
      </el-table-column>
      <el-table-column
        prop="documentType"
        header-align="center"
        align="center"
        label="证件类型">
      </el-table-column>
      <el-table-column
        prop="documentNumber"
        header-align="center"
        align="center"
        label="证件号">
      </el-table-column>
      <el-table-column
        prop="birthday"
        header-align="center"
        align="center"
        label="出生日期">
      </el-table-column>
      <el-table-column
        prop="sex"
        header-align="center"
        align="center"
        label="性别">
      </el-table-column>
      <el-table-column
        prop="crewType"
        header-align="center"
        align="center"
        label="船员类型">
      </el-table-column>
      <el-table-column
        prop="political"
        header-align="center"
        align="center"
        label="政治面貌">
      </el-table-column>
      <el-table-column
        prop="maritalStatus"
        header-align="center"
        align="center"
        label="婚姻状况">
      </el-table-column>
      <el-table-column
        prop="bloodType"
        header-align="center"
        align="center"
        label="血型">
      </el-table-column>
      <el-table-column
        prop="experienceSailing"
        header-align="center"
        align="center"
        label="航海经验">
      </el-table-column>
      <el-table-column
        prop="repatriationArea"
        header-align="center"
        align="center"
        label="遣返地">
      </el-table-column>
      <el-table-column
        prop="technicalSkill"
        header-align="center"
        align="center"
        label="特殊技能">
      </el-table-column>
      <el-table-column
        prop="otherPhone"
        header-align="center"
        align="center"
        label="其他联络电话">
      </el-table-column>
      <el-table-column
        prop="postalAddress"
        header-align="center"
        align="center"
        label="通讯地址">
      </el-table-column>
      <el-table-column
        prop="eMail"
        header-align="center"
        align="center"
        label="电子邮箱">
      </el-table-column>
      <el-table-column
        prop="emergencyContact"
        header-align="center"
        align="center"
        label="紧急联络人">
      </el-table-column>
      <el-table-column
        prop="relationship"
        header-align="center"
        align="center"
        label="与本人关系">
      </el-table-column>
      <el-table-column
        prop="relationshipPhone"
        header-align="center"
        align="center"
        label="关系人手机号">
      </el-table-column>
      <el-table-column
        prop="relationshipOtherPhone"
        header-align="center"
        align="center"
        label="关系人其他联络电话">
      </el-table-column>
      <el-table-column
        prop="createUserIp"
        header-align="center"
        align="center"
        label="创建IP">
      </el-table-column>
      <el-table-column
        prop="affiliatedCompany"
        header-align="center"
        align="center"
        label="所属公司">
      </el-table-column>
      <el-table-column
        prop="createUserId"
        header-align="center"
        align="center"
        label="创建人">
      </el-table-column>-->
      <!-- <el-table-column
        prop="school"
        header-align="center"
        align="center"
        label="毕业院校">
      </el-table-column>
      <el-table-column
        prop="education"
        header-align="center"
        align="center"
        label="最高学历">
      </el-table-column>
      <el-table-column
        prop="certificate"
        header-align="center"
        align="center"
        label="学历证号">
      </el-table-column>
      <el-table-column
        prop="graduationTime"
        header-align="center"
        align="center"
        label="毕业时间">
      </el-table-column>
      <el-table-column
        prop="major"
        header-align="center"
        align="center"
        label="专业">
      </el-table-column>
      <el-table-column
        prop="englishProficiency"
        header-align="center"
        align="center"
        label="英文水平">
      </el-table-column>
      <el-table-column
        prop="otherLanguages"
        header-align="center"
        align="center"
        label="其他语种">
      </el-table-column>
      <el-table-column
        prop="otherLanguageProficiency"
        header-align="center"
        align="center"
        label="语言水平">
      </el-table-column>-->
      <el-table-column prop="seekingJob" header-align="center" align="center" label="寻求职务"></el-table-column>
      <!-- <el-table-column
        prop="shipType"
        header-align="center"
        align="center"
        label="船舶类型">
      </el-table-column>
      <el-table-column
        prop="navigationArea"
        header-align="center"
        align="center"
        label="航区">
      </el-table-column>
      <el-table-column
        prop="deadweightTonnage"
        header-align="center"
        align="center"
        label="载重吨位">
      </el-table-column>-->
      <el-table-column prop="salaryEquirement" header-align="center" align="center" label="薪资要求"></el-table-column>
      <el-table-column prop="currency" header-align="center" align="center" label="币种"></el-table-column>
      <el-table-column prop="otherRequirements" header-align="center" align="center" label="其他要求"></el-table-column>
      <el-table-column prop="crewStatus" header-align="center" align="center" label="船员状态"></el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" label="创建时间"></el-table-column>
      <el-table-column prop="remarks" header-align="center" align="center" label="备注"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="160" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.crewId)">修改</el-button>
          <el-button type="text" size="small" @click="dispatchHandle(scope.row.crewId)">派遣</el-button>
          <el-button type="text" size="small" @click="certificatemanagement(scope.row.crewId)">证书</el-button>
          <el-button
            type="text"
            size="small"
            @click="contractinfoaddOrUpdateHandle(scope.row.crewId)"
          >合同</el-button>
          <!-- <el-button type="text" size="small" @click="detailsHandle(scope.row.crewId)">详情</el-button> -->
          <el-button type="text" size="small" @click="detailsHandleBox(scope.row.crewId)">详情</el-button>
          <el-dropdown @command="handleCommand" trigger="click">
            <span class="el-dropdown-link" style="color: #17B3A3;font-size: 12px;cursor: pointer;margin-left:10px;">
              导出<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="1">渤海轮渡</el-dropdown-item>
              <el-dropdown-item command="2">社会船员</el-dropdown-item>
              <el-dropdown-item command="3">中远海运</el-dropdown-item>
              <el-dropdown-item command="4">海员简历</el-dropdown-item>
              <!-- <el-dropdown-item command="5">常用简历</el-dropdown-item> -->
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <el-button type="text" size="small" @click="deleteHandle(scope.row.crewId)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      :data-variety="dataVariety"
      :details-box="detailsBox"
      @refreshDataList="getDataList"
    ></add-or-update>
    <!-- 弹窗, 派遣 -->
    <dispatch v-if="dispatchVisible" ref="dispatch" @refreshDataList="getDataList"></dispatch>
    <newdispat v-if="visibleNewdispat" ref="newdispat" @refreshDataList="getDataList"></newdispat>
    <!-- 新增合同 -->
    <contractinfo-add-or-update
      v-if="contractinfoaddOrUpdateVisible"
      ref="contractinfoaddOrUpdate"
      @refreshDataList="getDataList"
    ></contractinfo-add-or-update>
    <!-- 新增证书 -->
    <certificatemanagement-add-or-update
      v-if="certificatemanagementVisible"
      ref="addOrUpdatecertificatemanagement"
      @refreshDataList="getDataList"
    ></certificatemanagement-add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "./crewinfo-add-or-update";
import Dispatch from "./dispatchinfo-add-or-update";
import newdispat from "./dispatchinfo-newdispat";
import ContractinfoAddOrUpdate from "./contractinfo-add-or-update";
import CertificatemanagementAddOrUpdate from "./certificatemanagement-add-or-update";
export default {
  data() {
    return {
      dataForm: {
        key: ""
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      dispatchVisible: false,
      visibleNewdispat: false,
      optionsCrewPost: [],
      optionsCertificateLevel: [],
      optionsCrewStatus: [],
      dataVariety: true,
      detailsBox: false,
      contractinfoaddOrUpdateVisible: false,
      certificatemanagementVisible: false,
      rowcrewId: null
    };
  },
  components: {
    AddOrUpdate,
    Dispatch,
    newdispat,
    ContractinfoAddOrUpdate,
    CertificatemanagementAddOrUpdate
  },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/generator/crewinfo/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.dataForm.key,
          crewPost: this.dataForm.crewPost,
          certificateLevel: this.dataForm.certificateLevel,
          crewStatus: this.dataForm.crewStatus,
          ageFrom: this.dataForm.ageFrom,
          ageTo: this.dataForm.ageTo
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });

      this.$http({
        url: this.$http.adornUrl(`/generator/datadictionary/info/${1}`),
        method: "get",
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.optionsCrewPost = data && data.code === 0 ? data.list : [];
      });

      this.$http({
        url: this.$http.adornUrl(`/generator/datadictionary/info/${7}`),
        method: "get",
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.optionsCertificateLevel = data && data.code === 0 ? data.list : [];
      });

      this.$http({
        url: this.$http.adornUrl(`/generator/datadictionary/info/${2}`),
        method: "get",
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.optionsCrewStatus = data && data.code === 0 ? data.list : [];
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      var _this = this;
      this.dataVariety = !this.dataVariety;
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        _this.detailsBox = true;
        this.$refs.addOrUpdate.init(id, 0);
      });
    },
    // 新增证书
    certificatemanagement(id) {
      var add = 0;
      this.certificatemanagementVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdatecertificatemanagement.init(id, add);
      });
    },
    // 重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 派遣
    dispatchHandle(id) {
      var add = 0;
      this.dispatchVisible = true;
      this.$nextTick(() => {
        this.$refs.dispatch.init(id, add);
      });
    },
    // 详情
    detailsHandle(id) {
      var _this = this;
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        _this.detailsBox = false;
        this.$refs.addOrUpdate.init(id, 1);
      });
    },
    // 详情------------------------
    detailsHandleBox(id) {
      var _this = this;
      this.visibleNewdispat = true;
      this.$nextTick(() => {
        this.$refs.newdispat.init(id, 1);
      });
    },
    handleCommand(command) {
      var _this = this
      // window.location = 'http://localhost:8080/renren-fast/generator/crewinfo/export' + command + '?crewId=' + _this.rowcrewId
      window.location = 'http://120.27.17.138/renren-fast/generator/crewinfo/export' + command + '?crewId=' + _this.rowcrewId
    },
    clickTable(row) {
      this.rowcrewId = row.crewId
    },
    // 删除
    deleteHandle(id) {
      var ids = id
        ? [id]
        : this.dataListSelections.map(item => {
            return item.crewId;
          });
      this.$confirm(
        `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        this.$http({
          url: this.$http.adornUrl("/generator/crewinfo/delete"),
          method: "post",
          data: this.$http.adornData(ids, false)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.getDataList();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    },
    contractinfoaddOrUpdateHandle(info) {
      console.log("info", info);
      var id = 0;
      this.contractinfoaddOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.contractinfoaddOrUpdate.init(id, 0, info);
      });
    }
  }
};
</script>
